home *** CD-ROM | disk | FTP | other *** search
/ Aminet 2 / Aminet AMIGA CDROM (1994)(Walnut Creek)[Feb 1994][W.O. 44790-1].iso / Aminet / comm / term / term34Source.lha / PrintPanel.c < prev    next >
C/C++ Source or Header  |  1993-07-16  |  11KB  |  406 lines

  1. /*
  2. **    PrintPanel.c
  3. **
  4. **    Control panel to set options for phonebook printing
  5. **
  6. **    Copyright © 1990-1993 by Olaf `Olsen' Barthel & MXM
  7. **        All Rights Reserved
  8. */
  9.  
  10. #include "termGlobal.h"
  11.  
  12. enum    {    GAD_FILE, GAD_SELECT_FILE, GAD_PLAIN, GAD_INCLUDE_SERIAL, GAD_INCLUDE_MODEM, GAD_INCLUDE_SCREEN,
  13.         GAD_INCLUDE_TERMINAL,GAD_INCLUDE_USER, GAD_INCLUDE_COMMENT, GAD_USE, GAD_CANCEL };
  14.  
  15. STATIC UBYTE    OutputFile[MAX_FILENAME_LENGTH] = "PRT:";
  16. STATIC ULONG    Flags = PRINT_SERIAL | PRINT_MODEM | PRINT_SCREEN | PRINT_TERMINAL | PRINT_USERNAME | PRINT_COMMENT;
  17. STATIC BYTE    Plain = FALSE;
  18.  
  19. STATIC struct Gadget *
  20. CreateAllGadgets(struct Gadget **GadgetArray,struct Gadget **GadgetList)
  21. {
  22.     struct Gadget        *Gadget;
  23.     struct NewGadget     NewGadget;
  24.     UWORD             Counter = 0;
  25.  
  26.     SZ_SizeSetup(Window -> WScreen,&UserFont,TRUE);
  27.  
  28.     memset(&NewGadget,0,sizeof(struct NewGadget));
  29.  
  30.     if(Gadget = CreateContext(GadgetList))
  31.     {
  32.         SZ_AddLeftOffset(SZ_LeftOffsetDelta(MSG_PRINTPANEL_OUTPUT_FILE_OR_DEVICE_GAD,MSG_PRINTPANEL_INCLUDE_COMMENT_GAD));
  33.  
  34.         SZ_SetWidth(SZ_Width(FILE_KIND,NULL,30,NULL));
  35.  
  36.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_OUTPUT_FILE_OR_DEVICE_GAD);
  37.         NewGadget . ng_GadgetID        = Counter;
  38.  
  39.         GadgetArray[Counter++] = Gadget = CreateGadget(STRING_KIND,Gadget,&NewGadget,
  40.             SZ_Adjust,        TRUE,
  41.             SZ_AutoWidth,        TRUE,
  42.             SZ_LeaveFolder,        TRUE,
  43.  
  44.             GTST_String,        OutputFile,
  45.             GTST_MaxChars,        255,
  46.         TAG_DONE);
  47.  
  48.         NewGadget . ng_GadgetID        = Counter;
  49.  
  50.         GadgetArray[Counter++] = Gadget = CreateGadget(FILE_KIND,Gadget,&NewGadget,
  51.             SZ_Adjust,    TRUE,
  52.             SZ_AutoWidth,    TRUE,
  53.             SZ_PlaceLeft,    TRUE,
  54.         TAG_DONE);
  55.  
  56.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_PLAIN_TEXT_GAD);
  57.         NewGadget . ng_GadgetID        = Counter;
  58.  
  59.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  60.             SZ_Adjust,    TRUE,
  61.             SZ_AutoWidth,    TRUE,
  62.  
  63.             GTCB_Checked,    Plain,
  64.         TAG_DONE);
  65.  
  66.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_INCLUDE_SERIAL_GAD);
  67.         NewGadget . ng_GadgetID        = Counter;
  68.  
  69.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  70.             SZ_Adjust,    TRUE,
  71.             SZ_AutoWidth,    TRUE,
  72.             SZ_AlignExtra,    TRUE,
  73.  
  74.             GTCB_Checked,    Flags & PRINT_SERIAL,
  75.         TAG_DONE);
  76.  
  77.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_INCLUDE_MODEM_GAD);
  78.         NewGadget . ng_GadgetID        = Counter;
  79.  
  80.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  81.             SZ_Adjust,    TRUE,
  82.             SZ_AutoWidth,    TRUE,
  83.  
  84.             GTCB_Checked,    Flags & PRINT_MODEM,
  85.         TAG_DONE);
  86.  
  87.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_INCLUDE_SCREEN_GAD);
  88.         NewGadget . ng_GadgetID        = Counter;
  89.  
  90.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  91.             SZ_Adjust,    TRUE,
  92.             SZ_AutoWidth,    TRUE,
  93.  
  94.             GTCB_Checked,    Flags & PRINT_SCREEN,
  95.         TAG_DONE);
  96.  
  97.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_INCLUDE_TERMINAL_GAD);
  98.         NewGadget . ng_GadgetID        = Counter;
  99.  
  100.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  101.             SZ_Adjust,    TRUE,
  102.             SZ_AutoWidth,    TRUE,
  103.  
  104.             GTCB_Checked,    Flags & PRINT_TERMINAL,
  105.         TAG_DONE);
  106.  
  107.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_INCLUDE_USER_NAME_GAD);
  108.         NewGadget . ng_GadgetID        = Counter;
  109.  
  110.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  111.             SZ_Adjust,    TRUE,
  112.             SZ_AutoWidth,    TRUE,
  113.  
  114.             GTCB_Checked,    Flags & PRINT_USERNAME,
  115.         TAG_DONE);
  116.  
  117.         NewGadget . ng_GadgetText    = LocaleString(MSG_PRINTPANEL_INCLUDE_COMMENT_GAD);
  118.         NewGadget . ng_GadgetID        = Counter;
  119.  
  120.         GadgetArray[Counter++] = Gadget = CreateGadget(CHECKBOX_KIND,Gadget,&NewGadget,
  121.             SZ_Adjust,    TRUE,
  122.             SZ_AutoWidth,    TRUE,
  123.  
  124.             GTCB_Checked,    Flags & PRINT_COMMENT,
  125.         TAG_DONE);
  126.  
  127.         SZ_ResetMaxWidth();
  128.  
  129.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_USE_GAD),0,NULL);
  130.         SZ_UpdateMaxWidth(BUTTON_KIND,LocaleString(MSG_GLOBAL_CANCEL_GAD),0,NULL);
  131.  
  132.         SZ_SetWidth(SZ_ResetMaxWidth());
  133.  
  134.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_USE_GAD);
  135.         NewGadget . ng_GadgetID        = Counter;
  136.         NewGadget . ng_Flags        = 0;
  137.  
  138.         GadgetArray[Counter++] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  139.             SZ_Adjust,    TRUE,
  140.             SZ_AutoWidth,    TRUE,
  141.             SZ_AlignExtra,    TRUE,
  142.             SZ_AlignLeft,    TRUE,
  143.             SZ_AlignBottom,    TRUE,
  144.         TAG_DONE);
  145.  
  146.         NewGadget . ng_GadgetText    = LocaleString(MSG_GLOBAL_CANCEL_GAD);
  147.         NewGadget . ng_GadgetID        = Counter;
  148.  
  149.         GadgetArray[Counter] = Gadget = CreateGadget(BUTTON_KIND,Gadget,&NewGadget,
  150.             SZ_Adjust,    TRUE,
  151.             SZ_AutoWidth,    TRUE,
  152.             SZ_AlignRight,    TRUE,
  153.         TAG_DONE);
  154.     }
  155.  
  156.     return(Gadget);
  157. }
  158.  
  159. VOID
  160. PrintPanel(struct Window *Window,struct List *PhoneList,LONG Count)
  161. {
  162.     struct Window    *PanelWindow;
  163.     struct Gadget    *GadgetList = NULL;
  164.     struct Gadget    *GadgetArray[GAD_CANCEL + 1];
  165.     BYTE         Result    = FALSE;
  166.  
  167.     if(CreateAllGadgets(GadgetArray,&GadgetList))
  168.     {
  169.         if(PanelWindow = OpenWindowTags(NULL,
  170.             WA_Left,    GetScreenLeft(Window) + (GetScreenWidth(Window) - SZ_GetWindowWidth()) / 2,
  171.             WA_Top,        GetScreenTop(Window) + (GetScreenHeight(Window) - SZ_GetWindowHeight())    / 2,
  172.             WA_Width,    SZ_GetWindowWidth(),
  173.             WA_Height,    SZ_GetWindowHeight(),
  174.  
  175.             WA_Activate,    TRUE,
  176.             WA_DragBar,    TRUE,
  177.             WA_DepthGadget,    TRUE,
  178.             WA_RMBTrap,    TRUE,
  179.             WA_DepthGadget,    TRUE,
  180.             WA_CloseGadget,    TRUE,
  181.             WA_CustomScreen,Window -> WScreen,
  182.  
  183.             WA_IDCMP,    IDCMP_GADGETDOWN | IDCMP_ACTIVEWINDOW | IDCMP_VANILLAKEY | IDCMP_RAWKEY | IDCMP_CLOSEWINDOW | BUTTONIDCMP | CHECKBOXIDCMP | STRINGIDCMP,
  184.  
  185.             WA_Title,    LocaleString(MSG_PRINTPANEL_OUTPUT_OPTIONS_TXT),
  186.         TAG_DONE))
  187.         {
  188.             struct IntuiMessage    *Massage;
  189.             ULONG             IClass,Code;
  190.             struct Gadget        *Gadget;
  191.             BYTE             Terminated = FALSE;
  192.  
  193.             UBYTE             DummyBuffer[MAX_FILENAME_LENGTH],
  194.                         *DummyChar;
  195.             struct FileRequester    *FileRequest;
  196.             STRPTR             Name;
  197.  
  198.             GuideContext(CONTEXT_PRINT);
  199.  
  200.             PushWindow(PanelWindow);
  201.  
  202.             AddGList(PanelWindow,GadgetList,(UWORD)-1,(UWORD)-1,NULL);
  203.             RefreshGList(GadgetList,PanelWindow,NULL,(UWORD)-1);
  204.             GT_RefreshWindow(PanelWindow,NULL);
  205.  
  206.             ActiveGadget = NULL;
  207.  
  208.             ClrSignal(SIG_BREAK);
  209.  
  210.             while(!Terminated)
  211.             {
  212.                 if(Wait(PORTMASK(PanelWindow -> UserPort) | SIG_BREAK) & SIG_BREAK)
  213.                     break;
  214.  
  215.                 while(!Terminated && (Massage = (struct IntuiMessage *)GT_GetIMsg(PanelWindow -> UserPort)))
  216.                 {
  217.                     IClass    = Massage -> Class;
  218.                     Code    = Massage -> Code;
  219.                     Gadget    = (struct Gadget *)Massage -> IAddress;
  220.  
  221.                     GT_ReplyIMsg(Massage);
  222.  
  223.                     KeySelect(GadgetArray,GAD_CANCEL,Code,PanelWindow,&Gadget,&IClass,&Code);
  224.  
  225.                     if(IClass == IDCMP_GADGETDOWN)
  226.                     {
  227.                         if((Gadget -> GadgetType & GTYP_GTYPEMASK) == GTYP_STRGADGET)
  228.                             ActiveGadget = Gadget;
  229.                     }
  230.  
  231.                     if(IClass == IDCMP_ACTIVEWINDOW && ActiveGadget)
  232.                         ActivateGadget(ActiveGadget,PanelWindow,NULL);
  233.  
  234.                     if(IClass == IDCMP_CLOSEWINDOW)
  235.                         Terminated = TRUE;
  236.  
  237.                     if(IClass == IDCMP_GADGETUP)
  238.                     {
  239.                         switch(Gadget -> GadgetID)
  240.                         {
  241.                             case GAD_SELECT_FILE:
  242.  
  243.                                 BlockWindow(PanelWindow);
  244.  
  245.                                 strcpy(DummyBuffer,SZ_GetString(GadgetArray[GAD_FILE]));
  246.  
  247.                                 if(DummyBuffer[0])
  248.                                 {
  249.                                     if(FilePart(DummyBuffer) == DummyBuffer)
  250.                                         DummyBuffer[0] = 0;
  251.                                     else
  252.                                     {
  253.                                         DummyChar = PathPart(DummyBuffer);
  254.  
  255.                                         *DummyChar = 0;
  256.                                     }
  257.  
  258.                                     DummyChar = FilePart(SZ_GetString(GadgetArray[GAD_FILE]));
  259.                                 }
  260.                                 else
  261.                                     DummyChar = "";
  262.  
  263.                                 if(!DummyChar[0])
  264.                                 {
  265.                                     DummyBuffer[0] = 0;
  266.  
  267.                                     DummyChar = LocaleString(MSG_PRINTPANEL_FILENAME_TXT);
  268.                                 }
  269.  
  270.                                 if(FileRequest = GetFile(LocaleString(MSG_PRINTPANEL_SELECT_OUTPUT_FILE_TXT),DummyBuffer,DummyChar,DummyBuffer,NULL,FALSE,FALSE,FALSE,LocaleString(MSG_GLOBAL_SELECT_TXT),TRUE))
  271.                                 {
  272.                                     GT_SetGadgetAttrs(GadgetArray[GAD_FILE],PanelWindow,NULL,
  273.                                         GTST_String,DummyBuffer,
  274.                                     TAG_DONE);
  275.  
  276.                                     FreeAslRequest(FileRequest);
  277.                                 }
  278.  
  279.                                 ReleaseWindow(PanelWindow);
  280.                                 break;
  281.  
  282.                             case GAD_USE:
  283.  
  284.                                 Terminated = TRUE;
  285.  
  286.                                 Plain = SZ_GetChecked(GadgetArray[GAD_PLAIN]);
  287.  
  288.                                 Flags = NULL;
  289.  
  290.                                 if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_SERIAL]))
  291.                                     Flags |= PRINT_SERIAL;
  292.  
  293.                                 if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_MODEM]))
  294.                                     Flags |= PRINT_MODEM;
  295.  
  296.                                 if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_SCREEN]))
  297.                                     Flags |= PRINT_SCREEN;
  298.  
  299.                                 if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_TERMINAL]))
  300.                                     Flags |= PRINT_TERMINAL;
  301.  
  302.                                 if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_USER]))
  303.                                     Flags |= PRINT_USERNAME;
  304.  
  305.                                 if(SZ_GetChecked(GadgetArray[GAD_INCLUDE_COMMENT]))
  306.                                     Flags |= PRINT_COMMENT;
  307.  
  308.                                 Name = SZ_GetString(GadgetArray[GAD_FILE]);
  309.  
  310.                                 if(Name[0])
  311.                                 {
  312.                                     strcpy(OutputFile,Name);
  313.  
  314.                                     Result = TRUE;
  315.                                 }
  316.  
  317.                                 break;
  318.  
  319.                             case GAD_CANCEL:
  320.  
  321.                                 Terminated = TRUE;
  322.                                 break;
  323.                         }
  324.                     }
  325.  
  326.                     ActiveGadget = NULL;
  327.                 }
  328.             }
  329.  
  330.             RemoveGList(PanelWindow,GadgetList,(UWORD)-1);
  331.  
  332.             PopWindow();
  333.  
  334.             CloseWindow(PanelWindow);
  335.         }
  336.     }
  337.  
  338.     if(Result)
  339.     {
  340.         LONG Error = 0;
  341.         BPTR File;
  342.  
  343.         if(File = Open(OutputFile,MODE_NEWFILE))
  344.         {
  345.             struct Window        *ReqWindow;
  346.             struct EasyStruct     Easy;
  347.  
  348.             Easy . es_StructSize    = sizeof(struct EasyStruct);
  349.             Easy . es_Flags        = NULL;
  350.             Easy . es_Title        = (UBYTE *)LocaleString(MSG_TERMAUX_TERM_REQUEST_TXT);
  351.             Easy . es_GadgetFormat    = (UBYTE *)LocaleString(MSG_PRINT_STOP_TXT);
  352.             Easy . es_TextFormat    = (UBYTE *)LocaleString(MSG_PRINT_PRINTING_PHONEBOOK_TXT);
  353.  
  354.             if(ReqWindow = BuildEasyRequest(Window,&Easy,NULL))
  355.             {
  356.                 struct PhoneNode    *TempNode;
  357.                 BYTE             Continue = TRUE;
  358.  
  359.                 if(Count > 0)
  360.                 {
  361.                     for(TempNode = (struct PhoneNode *)PhoneList -> lh_Head ; Continue && TempNode -> VanillaNode . ln_Succ ; TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ)
  362.                     {
  363.                         if(TempNode -> Entry -> Count >= 0)
  364.                             Continue = PrintEntry(File,ReqWindow,Plain,&Error,TempNode -> Entry,Flags);
  365.                     }
  366.                 }
  367.                 else
  368.                 {
  369.                     for(TempNode = (struct PhoneNode *)PhoneList -> lh_Head ; Continue && TempNode -> VanillaNode . ln_Succ ; TempNode = (struct PhoneNode *)TempNode -> VanillaNode . ln_Succ)
  370.                         Continue = PrintEntry(File,ReqWindow,Plain,&Error,TempNode -> Entry,Flags);
  371.                 }
  372.  
  373.                 FreeSysRequest(ReqWindow);
  374.             }
  375.  
  376.             Close(File);
  377.  
  378.             if(PathPart(OutputFile) != OutputFile)
  379.             {
  380.                 AddProtection(OutputFile,FIBF_EXECUTE);
  381.  
  382.                 if(Config -> MiscConfig -> CreateIcons)
  383.                     AddIcon(OutputFile,FILETYPE_TEXT,TRUE);
  384.             }
  385.         }
  386.         else
  387.             Error = IoErr();
  388.  
  389.         if(Error)
  390.         {
  391.             STRPTR ErrorString;
  392.  
  393.             if(Fault(Error,"",SharedBuffer,MAX_FILENAME_LENGTH))
  394.                 ErrorString = SharedBuffer;
  395.             else
  396.                 ErrorString = "???";
  397.  
  398.             MyEasyRequest(Window,LocaleString(MSG_PRINT_ERROR_TXT),LocaleString(MSG_GLOBAL_CONTINUE_TXT),Error,ErrorString);
  399.         }
  400.     }
  401.  
  402.     ActiveGadget = NULL;
  403.  
  404.     FreeGadgets(GadgetList);
  405. }
  406.